package com.cqc.mebaidumapdemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cqc.mebaidumapdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ${cqc} on 2017/7/5.
 */

public class MainAdapter extends BaseAdapter {

    String[] arrays;

    public MainAdapter(Context context) {
        super();
        arrays = context.getResources().getStringArray(R.array.map_types);
    }

    @Override
    public int getCount() {
        return arrays.length;
    }

    @Override
    public Object getItem(int i) {
        return arrays[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_main, viewGroup, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv2.setText(arrays[i]);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv2)
        TextView tv2;
        @BindView(R.id.tv3)
        TextView tv3;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
